package controller;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.mybatis.mapper.UserinfoMapper;
import com.mybatis.po.Userinfo;

@Controller
public class Register {
	@Autowired
	private UserinfoMapper userinfoMapper;
	@RequestMapping("/register")
	@ResponseBody
	public Map<String, Object> register(@RequestBody Userinfo userinfo) {
//		//查询一个用户
//		MyUser mu=userMapper.selectUserById(1);
//		System.out.println(mu);
		//添加一个用户
		HashMap<String, Object> result = new HashMap<>();
		System.out.println(userinfo.getName());
		try {
			Userinfo addmu=new Userinfo();
			addmu.setId(userinfo.getId());
			addmu.setName(userinfo.getName());
			addmu.setPwd(userinfo.getPwd());
			addmu.setIdentity(userinfo.getIdentity());
			userinfoMapper.addUser(addmu);
			result.put("mess", "1");
		}catch(Exception e) {
			result.put("mess", "0");
			System.out.print(e);
		}
//		//修改一个用户
//		MyUser updatemu=new MyUser();
//		updatemu.setUid(1);
//		updatemu.setUname("张三");
//		updatemu.setUsex("女");
//		//删除一个用户
//		userMapper.deleteUser(3);
//		//查询所有用户
//		List<MyUser> listMu=userMapper.selectAllUser();
//		for(MyUser myUser:listMu) {
//			System.out.println(myUser);
//		}
		return result;
	}
	
}
